home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 1 / Gekikoh Dennoh Club Vol. 1 (Japan).7z / Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin / cone / esc.c < prev    next >
C/C++ Source or Header  |  1997-06-06  |  11KB  |  620 lines

  1. /*
  2.     超突貫シェル???
  3.     ESC
  4. */
  5.  
  6. #include    <stdio.h>
  7. #include    <string.h>
  8.  
  9.  
  10.  
  11. typedef    enum    {
  12.     EXIT_ESC,
  13.     USER_FUNC,
  14.     SYSTEM,
  15.     ADD_IVENT,
  16.     IDLE,
  17.     WRITE_TEXT,
  18.     TITLE,
  19.     JPG_UL,
  20.     JPG_UR,
  21.     JPG_DL,
  22.     JPG_DR,
  23.     PIC_UL,
  24.     PIC_UR,
  25.     PIC_DL,
  26.     PIC_DR
  27. } FUNC_NUMBER;
  28.  
  29.  
  30. typedef    struct    {
  31.     char    func_name[64+1];    //関数名
  32.     int    func_argc;        //コマンドラインのアレ
  33.     char    func_argv[16][64+1];    //コマンドライン
  34. } FUNC_INFO;
  35.  
  36.  
  37. typedef    struct    {
  38.     int    px,py,ox,oy;        //ボタン位置
  39.     char    func_name[64+1];    //関数名
  40. } IVENT_LIST;
  41.  
  42.  
  43. typedef    struct    {
  44.     int    mx,my;        //ボタン位置
  45. } PUSH_INFO;
  46.  
  47.  
  48. IVENT_LIST    global_list[4];
  49.  
  50.  
  51. int    main(argc,argv)
  52. int    argc;
  53. char    *argv[];
  54. {
  55.     Init();
  56.  
  57.     if( argc==2 ){
  58.         Escape(argv[1],"main");
  59.     }
  60.     else{
  61.         printf("usage : ESC filename\n");
  62.     }
  63.  
  64. }
  65.  
  66.  
  67. /*
  68.     グローバルボタン設定
  69. */
  70. int    Init()
  71. {
  72.     global_list[0].px=488;
  73.     global_list[0].py=4;
  74.     global_list[0].ox=16;
  75.     global_list[0].oy=16;
  76.     strcpy(global_list[0].func_name,"exit");
  77.  
  78.     global_list[1].px=8;
  79.     global_list[1].py=56;
  80.     global_list[1].ox=20;
  81.     global_list[1].oy=20;
  82.     strcpy(global_list[1].func_name,"return");
  83.  
  84.     screen(1,3,1,1);
  85.     apic_load("esc_form.pic",0,0);
  86.  
  87. }
  88.  
  89.  
  90.  
  91. /*
  92.     終了
  93. */
  94. int    Term()
  95. {
  96.     screen(2,0,1,1);
  97.     exit(1);
  98. }
  99.  
  100.  
  101. /*
  102.     ESC実行
  103.  
  104.     script        スクリプトファイル名
  105.     funcname    関数名
  106.  
  107.     0未満で異常終了
  108. */
  109. int    Escape(script,funcname)
  110. char    *script,*funcname;
  111. {
  112.     int    res=0,fres;
  113.     FILE    *script_fp;
  114.     char    linebuf[256],*lptr;    //ファイルリード用ラインバッファ
  115.     char    search_string[256],*sptr;    //サーチ文字格納
  116.     FUNC_INFO    func_info[16];        //実行コマンド(数は適当)
  117.     int    fn=0,last_func;            //実行ナンバー
  118.     IVENT_LIST    ivent_list[16];        //イベントリスト
  119.     int    in=0,last_ivent;        //イベントナンバー
  120.     int    md,mbl,mbr,mx,my;
  121.     PUSH_INFO    push_info;        //退避情報
  122.     
  123.     
  124.     cls();
  125.     OS_CUROF();
  126.     C_FNKMOD(2);
  127.     
  128.     //Location
  129.     fill(80,88,420,106,rgb(27,27,27));
  130.     symbol(80,88,script,1,1,1,rgb(1,1,1),0);
  131.     
  132.     //mes
  133.     {
  134.         char    *mes,buf[256];
  135.         mes=buf;
  136.         sprintf(mes,"%sを処理中",funcname);
  137.         PrintMes(mes);
  138.     }
  139.     
  140.     mouse(0);
  141.     mouse(1);
  142.     mouse(4);
  143.  
  144.     script_fp=fopen(script,"rt");
  145.     if( script_fp==NULL ){
  146.         res=-1;
  147.         printf("スクリプトファイルが開けません");
  148.         getch();
  149.         goto quick_exit;
  150.     }
  151.  
  152.     //検索関数名の設定
  153.     sptr=search_string;
  154.     strcpy(sptr,"func ");
  155.     strcat(sptr,funcname);
  156.     strcat(sptr,"()");
  157.  
  158.     
  159.     while(1){
  160.         fres=fgets(linebuf,256,script_fp);
  161.         if( fres==NULL ){
  162.             break;    //ファイルを読み込み終わった
  163.         }
  164.         if( linebuf[0]=='/' || linebuf[0]=='\x0' || linebuf[0]=='\x0d' || linebuf[0]=='\x0a' ){
  165.             continue;
  166.         }
  167.         delcrlf(linebuf);
  168.         fres=strcmp(linebuf,search_string);
  169.         if( fres==0 ){
  170.             //関数名発見
  171.             fn=0;
  172.             while(1){
  173.                 fres=fgets(linebuf,256,script_fp);
  174.                 if( fres==NULL ){    //異常終了?
  175.                     goto quick_exit;
  176.                 }
  177.                 if( linebuf[0]=='/' || linebuf[0]=='\x0' || linebuf[0]=='\x0d' || linebuf[0]=='\x0a' ){
  178.                     continue;
  179.                 }
  180.                 delcrlf(linebuf);
  181.                 if( strcmp("endfunc",linebuf)==0 ){
  182.                     goto read_escfile_exit;
  183.                 }
  184.                 fres=GetFuncInfo(linebuf,&func_info[fn]);
  185.                 fn++;
  186.             }
  187.             break;
  188.         }
  189.     }
  190.  
  191.  
  192. read_escfile_exit:
  193.     fclose(script_fp);
  194.     
  195.     last_func=fn-1;
  196.     PushInfo(&push_info);
  197.     DrawFuncInfo(script,&func_info,last_func);
  198.     PopInfo(&push_info);
  199.     mouse(1);
  200.     mouse(4);
  201.     
  202.     //mes
  203.     PrintMes("読み終わりました");
  204.     
  205.     in=0;
  206.     for( fn=0;fn<=last_func;fn++ ){
  207.         char    comline[256],*cl;
  208.         fres=GetFuncNumber(&(func_info[fn]));
  209.         switch( fres ){
  210.             //イベント追加
  211.             case ADD_IVENT:
  212.                 strcpy(ivent_list[in].func_name,func_info[fn].func_argv[0]);
  213.                 sscanf(func_info[fn].func_argv[1],"%d,%d,%d,%d",
  214.                 &(ivent_list[in].px),&(ivent_list[in].py),&(ivent_list[in].ox),&(ivent_list[in].oy));
  215.                 in++;
  216.             break;
  217.             case IDLE:
  218.                 last_ivent=in-1;
  219.                 while(1){
  220.                     mspos(&mx,&my);
  221.                     msstat(&md,&md,&mbl,&mbr);
  222.                     if( mbl==-1 ){
  223.                         //ローカルボタンイベント
  224.                         for( in=0;in<=last_ivent;in++ ){
  225.                             if(
  226.                             mx>ivent_list[in].px && my>ivent_list[in].py && 
  227.                             mx<(ivent_list[in].px+ivent_list[in].ox) && my<(ivent_list[in].py+ivent_list[in].oy)
  228.                             ){
  229.                                 PushInfo(&push_info);
  230.                                 Escape(script,ivent_list[in].func_name);
  231.                                 DrawFuncInfo(script,&func_info,last_func);
  232.                                 PrintMes("復帰完了");
  233.                                 PopInfo(&push_info);
  234.                             }
  235.                         }
  236.                         //グローバルボタンイベント
  237.                         for( in=0;in<=1;in++ ){
  238.                             if(
  239.                             mx>global_list[in].px && my>global_list[in].py && 
  240.                             mx<(global_list[in].px+global_list[in].ox) && my<(global_list[in].py+global_list[in].oy)
  241.                             ){
  242.                                 if( strcmpi(global_list[in].func_name,"exit")==0 ){
  243.                                     Term();
  244.                                 }
  245.                                 if( strcmpi(global_list[in].func_name,"return")==0 ){
  246.                                     goto quick_exit;
  247.                                 }
  248.                             }
  249.                         }
  250.                     }
  251.                     if( mbl==-1 && mbr==-1 ){
  252.                         break;
  253.                     }
  254.                 }
  255.             break;
  256.         }
  257.     }
  258.  
  259.  
  260.     
  261. quick_exit:
  262.     PrintMes("復帰中");
  263.     return(0);
  264. }
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271. int    DrawFuncInfo(script,func_info,last_func)
  272. char    *script;
  273. FUNC_INFO    *func_info;
  274. int    last_func;
  275. {
  276.     int    fn,fres;
  277.  
  278.     for( fn=0;fn<=last_func;fn++ ){
  279.         char    comline[256],*cl;
  280.         fres=GetFuncNumber(&func_info[fn]);
  281.         switch( fres ){
  282.             case SYSTEM:
  283.                 Func__system(&func_info[fn]);
  284.             break;
  285.             case JPG_UL:
  286.                 Func__jpg_load_ul(&func_info[fn]);
  287.             break;
  288.             case JPG_UR:
  289.                 Func__jpg_load_ur(&func_info[fn]);
  290.             break;
  291.             case JPG_DL:
  292.                 Func__jpg_load_dl(&func_info[fn]);
  293.             break;
  294.             case JPG_DR:
  295.                 Func__jpg_load_dr(&func_info[fn]);
  296.             break;
  297.             
  298.             case PIC_UL:
  299.                 apic_load(func_info[fn].func_argv[0],8,128);
  300.             break;
  301.             case PIC_UR:
  302.                 apic_load(func_info[fn].func_argv[0],248,128);
  303.             break;
  304.             case PIC_DL:
  305.                 apic_load(func_info[fn].func_argv[0],8,308);
  306.             break;
  307.             case PIC_DR:
  308.                 apic_load(func_info[fn].func_argv[0],248,308);
  309.             break;
  310.             
  311.             case WRITE_TEXT:
  312.                 WriteText(func_info[fn].func_argv[0]);
  313.             break;
  314.             case USER_FUNC:
  315.                 Escape(script,func_info[fn].func_argv[0]);
  316.             break;
  317.             case EXIT_ESC:
  318.                 Term();
  319.             break;
  320.             case TITLE:
  321.                 PrintTitle(func_info[fn].func_argv[0]);
  322.             break;
  323.             
  324.         }
  325.     }
  326. }
  327.  
  328.  
  329.  
  330.  
  331. /*
  332.     文字列からCRLFを取り除く
  333. */
  334. int    delcrlf(ptr)
  335. char    *ptr;
  336. {
  337.     while( !(*ptr=='\x0d' || *ptr=='\x0a' || *ptr=='\x00') ){
  338.         ptr++;
  339.     }
  340.     *ptr=NULL;
  341. }
  342.  
  343.  
  344.  
  345. /*
  346.     関数
  347. */
  348. int    GetFuncInfo(linebuf,func_info)
  349. char    *linebuf;
  350. FUNC_INFO    *func_info;
  351. {
  352.     int    res=0;
  353.     char    *source,*dest,*av;
  354.     int    ac;
  355.     
  356.     source=linebuf;
  357.     //関数名検出
  358.     //頭の空白スキップ
  359.     while(1){
  360.         if( *source=='\t' || *source==' ' ){
  361.             source++;
  362.         }
  363.         else{
  364.             if( *source=='\n' || *source==NULL ){
  365.                 res=-1;
  366.                 goto quick_exit;
  367.             }
  368.             break;
  369.         }
  370.     }
  371.     //関数名摘出
  372.     dest=func_info->func_name;
  373.     while(1){
  374.         if( *source=='(' ){    //関数名終わり
  375.             *dest=NULL;
  376.             source++;
  377.             break;
  378.         }
  379.         if( *source=='\n' ){    //他にも構文解析が必要
  380.             res=-2;
  381.             goto quick_exit;
  382.         }
  383.         *dest++=*source++;
  384.     }
  385.  
  386.     //パラメ検出
  387.     ac=0;
  388.     while(1){
  389.         //頭の"検索
  390.         while(1){
  391.             if( *source=='"' ){
  392.                 source++;
  393.                 break;
  394.             }
  395.             //エラーチェック入れること
  396.             source++;
  397.         }
  398.         
  399.         //中身抜き出し
  400.         dest=&(func_info->func_argv[ac][0]);
  401.         while(1){
  402.             if( *source=='"' ){
  403.                 *dest=NULL;
  404.                 source++;
  405.                 break;
  406.             }
  407.             //エラーチェック入れること
  408.             *dest++=*source++;
  409.         }
  410.         
  411.         
  412.         //後始末
  413.         while(1){
  414.             if( *source==',' ){
  415.                 ac++;
  416.                 source++;
  417.                 break;
  418.             }
  419.             if( *source==')' ){
  420.                 goto av_end;
  421.             }
  422.             //エラーチェック入れること
  423.         }
  424. av_next:
  425.         ;
  426.     }
  427. av_end:
  428.     func_info->func_argc=ac+1;
  429.  
  430.     
  431. quick_exit:
  432.     return(res);
  433. }
  434.  
  435.  
  436.  
  437.  
  438. /*
  439.     関数の番号を返す
  440. */
  441. FUNC_NUMBER    GetFuncNumber(func_info)
  442. FUNC_INFO    *func_info;
  443. {
  444.     int    res=USER_FUNC;
  445.  
  446.     if( strcmpi("system",func_info->func_name)==0 ){
  447.         res=SYSTEM;
  448.         goto quick_exit;
  449.     }
  450.     
  451.     if( strcmpi("jpg_load_ul",func_info->func_name)==0 ){
  452.         res=JPG_UL;
  453.         goto quick_exit;
  454.     }
  455.     if( strcmpi("jpg_load_ur",func_info->func_name)==0 ){
  456.         res=JPG_UR;
  457.         goto quick_exit;
  458.     }
  459.     if( strcmpi("jpg_load_dl",func_info->func_name)==0 ){
  460.         res=JPG_DL;
  461.         goto quick_exit;
  462.     }
  463.     if( strcmpi("jpg_load_dr",func_info->func_name)==0 ){
  464.         res=JPG_DR;
  465.         goto quick_exit;
  466.     }
  467.  
  468.     if( strcmpi("pic_load_ul",func_info->func_name)==0 ){
  469.         res=PIC_UL;
  470.         goto quick_exit;
  471.     }
  472.     if( strcmpi("pic_load_ur",func_info->func_name)==0 ){
  473.         res=PIC_UR;
  474.         goto quick_exit;
  475.     }
  476.     if( strcmpi("pic_load_dl",func_info->func_name)==0 ){
  477.         res=PIC_DL;
  478.         goto quick_exit;
  479.     }
  480.     if( strcmpi("pic_load_dr",func_info->func_name)==0 ){
  481.         res=PIC_DR;
  482.         goto quick_exit;
  483.     }
  484.  
  485.     if( strcmpi("write_text",func_info->func_name)==0 ){
  486.         res=WRITE_TEXT;
  487.         goto quick_exit;
  488.     }
  489.     if( strcmpi("mbl_down",func_info->func_name)==0 ){
  490.         res=ADD_IVENT;
  491.         goto quick_exit;
  492.     }
  493.     if( strcmpi("idle",func_info->func_name)==0 ){
  494.         res=IDLE;
  495.         goto quick_exit;
  496.     }
  497.     if( strcmpi("exit",func_info->func_name)==0 ){
  498.         res=EXIT_ESC;
  499.         goto quick_exit;
  500.     }
  501.     if( strcmpi("title",func_info->func_name)==0 ){
  502.         res=TITLE;
  503.         goto quick_exit;
  504.     }
  505.  
  506. quick_exit:
  507.     return(res);
  508. }
  509.  
  510.  
  511.  
  512.  
  513.  
  514. /*****************************************************
  515.     内部関数
  516. ******************************************************/
  517.  
  518. int    Func__system(func_info)
  519. FUNC_INFO    *func_info;
  520. {
  521.     system(func_info->func_argv[0]);
  522. }
  523.  
  524.  
  525.  
  526. int    Func__jpg_load_ul(func_info)
  527. FUNC_INFO    *func_info;
  528. {
  529.     char    *cl,comline[256];
  530.  
  531.     cl=comline;
  532.     strcpy(cl,"JPEGED -N -F3 -L8,128,247,307 ");
  533.     strcat(cl,func_info->func_argv[0]);
  534.     strcat(cl," > NUL ");
  535.     system(comline);
  536. }
  537.  
  538.  
  539.  
  540. int    Func__jpg_load_ur(func_info)
  541. FUNC_INFO    *func_info;
  542. {
  543.     char    *cl,comline[256];
  544.  
  545.     cl=comline;
  546.     strcpy(cl,"JPEGED -N -F3 -L248,128,487,307 ");
  547.     strcat(cl,func_info->func_argv[0]);
  548.     strcat(cl," > NUL ");
  549.     system(comline);
  550. }
  551.  
  552.  
  553.  
  554. int    Func__jpg_load_dl(func_info)
  555. FUNC_INFO    *func_info;
  556. {
  557.     char    *cl,comline[256];
  558.  
  559.     cl=comline;
  560.     strcpy(cl,"JPEGED -N -F3 -L8,308,247,487 ");
  561.     strcat(cl,func_info->func_argv[0]);
  562.     strcat(cl," > NUL ");
  563.     system(comline);
  564. }
  565.  
  566.  
  567.  
  568. int    Func__jpg_load_dr(func_info)
  569. FUNC_INFO    *func_info;
  570. {
  571.     char    *cl,comline[256];
  572.  
  573.     cl=comline;
  574.     strcpy(cl,"JPEGED -N -F3 -L248,308,487,487 ");
  575.     strcat(cl,func_info->func_argv[0]);
  576.     strcat(cl," > NUL ");
  577.     system(comline);
  578. }
  579.  
  580.  
  581.  
  582. int    PushInfo(push_info)
  583. PUSH_INFO    *push_info;
  584. {
  585.     mspos(&(push_info->mx),&(push_info->my));
  586. }
  587.  
  588.  
  589.  
  590. int    PopInfo(push_info)
  591. PUSH_INFO    *push_info;
  592. {
  593.     mouse(1);
  594.     mouse(4);
  595.     setmspos(push_info->mx,push_info->my);
  596. }
  597.  
  598.  
  599.  
  600.  
  601. int    PrintMes(mes)
  602. {
  603.     fill(72,492,324,504,rgb(23,23,23));
  604.     symbol(72,492,mes,1,1,0,rgb(1,1,1),0);
  605. }
  606.  
  607.  
  608.  
  609.  
  610. int    PrintTitle(mes)
  611. {
  612.     fill(24,6,488,22,rgb(0,0,25));
  613.     symbol(24,6,mes,1,1,1,rgb(27,27,27),0);
  614. }
  615.  
  616.  
  617.  
  618.  
  619.  
  620.